<?php
namespace Home\Controller;
use Think\Controller;
use Think\Verify;

class IndexController extends Controller
{
    public function index()
    {
        $this->display();

    }

    public function login()
    {
        if (session('?username'))
        {
            session('[destroy]');
            //$this->error("该账号已登录，请不要重复登陆", 'javascript:history.back(-1);', 1);
        }else{
            if ($_POST['username'] != "") {
                $name = $_POST['username'];
                $pass = $_POST['password'];
                $theuser = M('theuser');
                $where['username'] = $name;
                $where['password'] = $pass;
                $sql = $theuser->where($where)->find();
                if ($sql) {
                    $_SESSION['islogin'] = 1;
                    $_SESSION['username'] = $sql['username'];
                    $_SESSION['password']=$sql['password'];
                    $_SESSION['id'] = $sql['id'];
                    $_SESSION['name'] = $sql['name'];
                    $where6['username']=session('username');
                    $arr=$theuser->where($where6)->select();
                    if($arr[0]['cengji']==0)
                    {
                        $this->success("操作成功！", U("Shouye/index"));
                    }elseif ($arr[0]['cengji']==10)
                    {
                        $this->success("欢迎来到管理员界面！", U("SuperManager/index"));
                    }
                    else{
                        $this->success("欢迎来到教师界面",U("Manager/index"));
                    }
                } else {
                    $this->error("登录失败,请重新登录", 'javascript:history.back(-1);', 3);
                }
            } else {
               // echo "<script>history.back(-1);</script>";
            }
        }
    }
    public function logout(){
        session('[destroy]');
        $this->redirect("Index/index");
    }
}